import java.io.Serializable;

public class Suffix {
  private Node originNode;
  private int beginIndex; //first char index, xreiazetai mono an den teleiwnw se node
  private int endIndex;

  public Suffix(Node originNode, int beginIndex, int endIndex) {
    this.originNode = originNode;
    this.beginIndex = beginIndex;
    this.endIndex = endIndex;
  }

  public boolean isExplicit() {
    return beginIndex > endIndex;
  }

  public boolean isImplicit() {
    return endIndex >= beginIndex;
  }

/*  public boolean canonize() {//MINE
    boolean inwhile = false;
    if (!isExplicit()) {
      Edge edge = originNode.findEdge(originNode.charAt(beginIndex));
      if (edge != null) { //as a result of constructing prefixed subtrees, we might not find an Edge
        int edgeSpan = edge.getSpan();
        while (edgeSpan <= getSpan()) {
//          System.out.println("IN CANONIZE WHILE");
          inwhile=true;
          beginIndex += edgeSpan + 1;
          originNode = edge.getEndNode();
          if (beginIndex <= endIndex) {
            edge = edge.getEndNode().findEdge(originNode.charAt(beginIndex));
            edgeSpan = edge.getSpan();
          }
        }
      }
    }
    return inwhile;
  }*/

  public int getSpan() {
    return endIndex - beginIndex;
  }

  public Node getOriginNode() {
    return originNode;
  }

  public void setOriginNode(Node newOriginNode) {
    originNode = newOriginNode;
  }

  public int getBeginIndex() {
    return beginIndex;
  }

  public void incBeginIndex() {
    beginIndex++;
  }

  public void setBeginIndex(int num) {
    beginIndex = num;
  }

/*  public void changeOriginNode() { //the parent node is the one that points to the next smallest suffix
    originNode = originNode.getSuffixNode();
  }*/

  public int getEndIndex() {
    return endIndex;
  }

  public void incEndIndex() {
    endIndex++;
  }
  
  public void setEndIndex(int num) {
    endIndex = num;
  }

  public void getStatus() {
    System.out.println("originNode: " + originNode + " beginIndex: " + beginIndex + " endIndex: " + endIndex);
  }
}
